#@tool
extends HBoxContainer

@onready var item_label = %item_label
@onready var item_comp_conatiner = %item_comp_container
@export var settingItemData:SettingItemData

var item_comp:ItemComp

func _ready():
	if settingItemData != null:
		init_item_comp(settingItemData)

# 初始化设置组件
func init_item_comp(msettingItemData:SettingItemData):
	item_label.text = msettingItemData.item_name
	item_comp = msettingItemData.item_comp.instantiate()
	item_comp_conatiner.add_child(item_comp)
	set_data()
	item_comp.data_changed.connect(_on_data_change)

# 存储数据的场景
func get_data():
	return item_comp._get_data()

# 从存储中读取数据的时候
func set_data():
	var data = GlobalVariables.settingData.get(settingItemData.setting_name)
	item_comp._set_data(data)

func _on_data_change():
	GlobalVariables.settingData.set(settingItemData.setting_name,get_data())
	

	

